﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO;

namespace DAO
{
    public static class HeThongDAO
    {
        public static List<HeThongDTO> LoadAll()
        {
            List<HeThongDTO> result = new List<HeThongDTO>();
            SqlConnection connection = new SqlConnection(DataProvider.ConnectionSting);
            try
            {
                SqlCommand command = new SqlCommand("sp_SelectAllHeThong", connection);
                command.CommandType = CommandType.StoredProcedure;

                connection.Open();

                SqlDataReader reader;
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    HeThongDTO tmp = new HeThongDTO();
                    tmp.ID = reader.GetInt32(0);
                    tmp.Ten = reader.GetString(1);
                    result.Add(tmp);
                }
                connection.Close();                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
            return result;
        }
    }
}
